package collection;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * List的三种遍历方式(ArrayList LinkedList Vector)
 */
@SuppressWarnings("all")
public class ListFor {

    public static void main(String[] args) {

        //List接口的实现子类 Vector LinkedList Arrylist

        //List list = new ArrayList();
        //List list = new Vector();
        List list = new LinkedList();

        list.add("jack");
        list.add("tom");
        list.add("鱼香肉丝");
        list.add("北京烤鸭");

        //遍历
        //1. 迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            System.out.println(obj);
        }

        System.out.println("=====增强 for=====");
        //2. 增强for
        for (Object o : list) {
            System.out.println("o=" + o);
        }

        System.out.println("=====普通 for====");
        //3. 使用普通for
        for (int i = 0; i < list.size(); i++) {
            System.out.println("对象 = "+list.get(i));
        }
    }
}
